/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: dings
 * Date: 2024-07-09
 * Time: 10:04
 */
import java.util.*;
 class ListNode {
    int val;
    ListNode next = null;

    ListNode(int val) {
        this.val = val;
    }
}
 class PalindromeList {
    public boolean chkPalindrome(ListNode A) {
        // write code here
        if (A == null) {
            return true;
        }
        ListNode fast = A;
        ListNode slow = A;

        while (fast != null && fast.next != null) {
            fast = fast.next.next;
            slow = slow.next;
        }

        ListNode cur = slow.next;
        ListNode curN = null;
        while (cur != null) {
            curN = cur.next;
            cur.next = slow;
            slow = cur;
            cur = curN;
        }
        ListNode newCur = A;
        while (slow != newCur) {
            if (slow.val != newCur.val) {
                return false;
            }
            if (newCur.next == slow) {
                return true;
            }
            slow = slow.next;
            newCur = newCur.next;
        }
        return true;
    }
}
public class Test {
}
